package com.atguigu.lease.common.conveter;

import com.atguigu.lease.model.enums.ItemType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;


public class StringToItemTypeConverter  implements Converter<String,ItemType> {
    @Override
    public ItemType convert(String source){
        //1获取枚举中的所有值
        ItemType[]values = ItemType.values();
        //2遍历所有的类型
        for (ItemType itemType : values){
            //3当前遍历的类型的code值和传进来的值相等
            if (itemType.getCode().equals(Integer.valueOf(source))){
                return itemType;
            }
        }
        //错误数据,抛出异常
        throw new IllegalArgumentException("非法的参数");
    }

}
